﻿;(function ($) {
    /*
    * 保养评分
    * */
    $.appoint = function (id,assetsId, isWebsocket, messageObj, isBatchDeal){
        /* 添加模态框 */
        var model = $("#modal-repair-handle");
        if (!model.length) {
            /* iziModal模态窗口:报修处理 */
            $('body').append('<div id="modal-repair-handle" class="score">' +
                '<div class="box-body">' +
                    '<div class="col-md-12">' +
                        '<div class="col-md-6" style="height: 100%;">' +
                            '<div class="col-md-12"><b class="text-aqua title">设备信息</b></div>' +
                            '<div class="col-md-6 thumbnail1" style="height: 4.6rem;display: none;"></div>' +
                            '<div class="col-md-6">' +
                                '<p></p>' +
                                '<p style="display: flex;"><span class="text-muted">设备名称：</span><a style="flex:1;" href="'+basePath+'/charts/overview/assets/page?deviceId='+assetsId+'" class="bxclAssetsName"></a></p>' +
                                '<p style="display: flex;"><span class="text-muted">设备型号：</span><span style="flex:1;" class="bxclModel"></span></p>' +
                                '<p style="display: flex;"><span class="text-muted">设备科室：</span><span style="flex:1;" class="bxclDepartment"></span></p>' +
                                '<p style="display: flex;"><span class="text-muted">设备分类：</span><span style="flex:1;" class="bxclCategory"></span></p>' +
                                '<p style="display: flex;"><span class="text-muted">生产厂家：</span><span style="flex:1;" class="bxclBrand"></span></p>' +
                                '<p style="display: flex;"><span class="text-muted">设备合同：</span><a style="flex:1;" class="contact-number-a" target="_blank"></a></p>' +
                            '</div>' +
                        '</div>' +
                        '<div class="col-md-6" style="height:100%;">' +
                            '<div class="col-md-12"><b class="text-aqua title">报修信息</b></div>' +
                            '<div class="col-md-6 thumbnail2" style="height: 4.6rem;display: none;"></div>' +
                            '<div class="col-md-6">' +
                                '<p></p>' +
                                '<p style="display: flex;"><span class="text-muted">报修时间：</span><span style="flex: 1;"  class="bxclRepairTime"></span></p>' +
                                '<p style="display: flex;"><span class="text-muted">报修人：</span><span style="flex: 1;" class="bxclUserName"></span></p>' +
                                '<p style="display: flex;"><span class="text-muted">联系电话：</span><span style="flex: 1;" class="bxclUserPhone"></span></p>' +
                                '<p style="display: flex;"><span class="text-muted">故障时间：</span><span style="flex: 1;" class="bxclFaultTime"></span></p>' +
                                '<p style="display: flex;"><span class="text-muted">故障描述：</span><span style="flex: 1;" class="bxclFault"></span></p>' +
                            '</div>' +
                        '</div>' +
                    '</div>' +
                    '<div class="col-md-12 repair-history" style="display: none;">' +
                        '<b class="text-aqua">维修历史</b>' +
                        '<p></p>' +
                        '<table class="table repair-history-table"><thead></thead><tbody></tbody></table>' +
                    '</div>' +
                    '<input type="hidden" class="assetsId">' +
                '</div>' +
                '<div class="box-body">' +
                    '<div class="col-md-12">' +
                        '<p></p>' +
                        '<div class="nav-tabs-custom">' +
                            '<ul class="nav nav-tabs">' +
                                '<li><a href="#tab_1" class="title" data-toggle="tab"><b>院内维修</b></a></li>' +
                                '<li class="active"><a href="#tab_2" class="title" data-toggle="tab"><b>维修商维修</b></a></li>' +
                            '</ul>' +
                        '</div>' +
                        '<div class="tab-content">' +
                            '<div class="tab-pane" id="tab_1">' +
                                '<form class="form-horizontal addDispatchInfoFromOwn" role="addDispatchInfoFromOwn" method="post" enctype="multipart/form-data">' +
                                    '<input type="hidden" class="id" name="id">' +
                                    '<input type="hidden" name="repairType" value="5001"> <!-- 维修类型5001属于内部维修 -->' +
                                    '<input type="hidden" name ="engineer" class="engineer">' +
                                    '<div class="hide">' +
                                        '<input type="file" class="file" multiple name="files" value="上传">' +
                                    '</div>' +
                                    '<!-- 工程师名字 -->' +
                                    '<div class="form-group">' +
                                        '<label for="engineerId" class="col-sm-3 control-label text-muted">工程师<span class="text-red"> *</span></label>' +
                                        '<div class="col-sm-8">' +
                                            '<select class="form-control engineerId" name="engineerId" style="width: 100%;"></select>' +
                                        '</div>' +
                                    '</div>' +
                                    '<div class="form-group hide">' +
                                        '<label for="cost" class="col-sm-3 control-label text-muted">维修费用</label>' +
                                        '<div class="col-sm-8">' +
                                            '<input type="text" class="form-control cost" name="cost" placeholder="">' +
                                        '</div>' +
                                    '</div>' +
                                    '<div class="form-group">' +
                                        '<label for="remark" class="col-sm-3 control-label text-muted">备注</label>' +
                                        '<div class="col-sm-8">' +
                                            '<textarea class="form-control remark" name="remark"></textarea>' +
                                        '</div>' +
                                    '</div>' +
                                '</form>' +
                                '<div class="box-footer text-center">' +
                                    '<button type="button" class="btn bg-aqua saveRegion" data-loading-text="保存中..." style="background: #ec1d6d;color: #303030;">保存</button>' +
                                    '<button class="btn btn-default cancel">取消</button>' +
                                '</div>' +
                            '</div>' +
                            '<div class="tab-pane active" id="tab_2">' +
                                '<form class="form-horizontal addDispatchInfoFromProvider" role="addDispatchInfoFromProvider" method="post" enctype="multipart/form-data">' +
                                    '<input type="hidden" class="id" name="id"><!-- 隐藏域(维修表id) -->' +
                                    '<input type="hidden" name="repairType" value="5002"><!-- 维修类型5002属于维修商修 -->' +
                                    '<input type="hidden" name ="engineer" class="engineer"><!-- 工程师名字 -->' +
                                    '<div class="form-group">' +
                                        '<label for="serviceProviderId" class="col-sm-3 control-label text-muted">维修商<span class="text-red"> *</span></label>' +
                                        '<div class="col-sm-8">' +
                                            '<select class="form-control serviceProviderId" name="serviceProviderId" style="width: 100%;"></select>' +
                                        '</div>' +
                                    '</div>' +
                                    '<div class="form-group">' +
                                        '<label for="engineerId" class="col-sm-3 control-label text-muted">工程师</label>' +
                                        '<div class="col-sm-8">' +
                                            '<select class="form-control engineerId" name="engineerId" style="width: 100%;;"></select>' +
                                        '</div>' +
                                    '</div>' +
                                    '<div class="form-group">' +
                                        '<label for="otherEngineer" class="col-sm-3 control-label text-muted">其他工程师</label>' +
                                        '<div class="col-sm-8">' +
                                            '<input type="text" class="form-control otherEngineer" name="otherEngineer" placeholder="">' +
                                        '</div>' +
                                    '</div>' +
                                    '<div class="form-group hide">' +
                                        '<label for="cost" class="col-sm-3 control-label text-muted">维修费用</label>' +
                                        '<div class="col-sm-8">' +
                                            '<input type="text" class="form-control cost" name="cost" placeholder="">' +
                                        '</div>' +
                                    '</div>' +
                                    '<div class="form-group">' +
                                        '<label for="maintenanceType" class="col-sm-3 control-label text-muted">维修方式</label>' +
                                        '<div class="col-sm-8">' +
                                            '<select class="form-control maintenanceType" name="maintenanceType">' +
                                                '<option value="0">无</option>' +
                                                '<option value="1">送修</option>' +
                                                '<option value="2">在院维修</option>' +
                                            '</select>' +
                                        '</div>' +
                                    '</div>' +
                                    '<div class="form-group hide send-div">' +
                                        '<label for="hospitalSendDate" class="col-sm-3 control-label text-muted">送出时间</label>' +
                                        '<div class="col-sm-8">' +
                                            '<input class="form-control hospitalSendDate" name="hospitalSendDate">' +
                                        '</div>' +
                                    '</div>' +
                                    '<div class="form-group hide send-number-div"> ' +
                                        '<label for="hospitalSendNumber" class="col-sm-3 control-label text-muted">送出快递单号</label>' +
                                        '<div class="col-sm-8">' +
                                            '<input class="form-control hospitalSendNumber" name="hospitalSendNumber">' +
                                        '</div>' +
                                    '</div>' +
                                    '<div class="form-group hide send-image-div">' +
                                        '<label for="files" class="col-sm-3 control-label text-muted">快递单号图片</label>' +
                                        '<div class="col-sm-8">' +
                                            '<input type="file" class="file files-upload" multiple name="files" value="上传">' +
                                        '</div>' +
                                    '</div>' +
                                    '<div class="form-group">' +
                                        '<label for="remark" class="col-sm-3 control-label text-muted">备注</label>' +
                                        '<div class="col-sm-8">' +
                                            '<textarea class="form-control remark" name="remark"></textarea>' +
                                        '</div>' +
                                    '</div>' +
                                '</form>' +
                                '<div class="box-footer text-center">' +
                                    '<button type="button" class="btn save">保存</button>' +
                                    '<button class="btn btn-default cancel">取消</button>' +
                                '</div>' +
                            '</div>' +
                        '</div>' +
                    '</div>' +
                '</div>' +
            '</div>');
            model = $("#modal-repair-handle");
            model.iziModal({
                title:"报修处理",
                headerColor: '#fff',
                theme: '',
                attached: '',
                icon: null,
                iconText: null,
                iconColor: '',
                rtl: false,
                width: 20 * rem,
                padding: 0,
                radius: 0.4 * rem,
                zindex: 10010,
                iframe: false,
                iframeHeight: 8 * rem,
                iframeURL: null,
                focusInput: false,
                group: '',
                loop: false,
                navigateCaption: true,
                navigateArrows: true,
                history: true,
                restoreDefaultContent: false,
                autoOpen: false,
                bodyOverflow: true,
                fullscreen: true,
                openFullscreen: false,
                closeOnEscape: false,
                overlay: true,
                overlayClose: false,
                overlayColor: 'rgba(0, 0, 0, 0.4)',
                timeout: false,
                timeoutProgressbar: false,
                pauseOnHover: false,
                timeoutProgressbarColor: 'rgba(255,255,255,0.5)',
                transitionIn: 'comingIn',
                transitionOut: 'comingOut',
                transitionInOverlay: 'fadeIn',
                transitionOutOverlay: 'fadeOut',
                onFullscreen: function(){},
                onResize: function(){},
                onOpening: function(){},
                onOpened: function(){},
                onClosing: function(){},
                onClosed: function(){
                    model.addClass('score');
                    model.find(".addDispatchInfoFromProvider").find(".engineerId").val(null).trigger("change");
                    model.find(".serviceProviderId").val(null).trigger("change");
                    model.find(".addDispatchInfoFromProvider").find(".engineerId").html("");
                    model.find(".addDispatchInfoFromOwn")[0].reset();
                    model.find(".addDispatchInfoFromProvider")[0].reset();
                    repairHistory.slideUp();
                    model.find('.thumbnail1').empty();
                    model.find('.thumbnail2').empty();
                }
            });
            own();
            provider();

            //model.find(".searchMaintenanceType").select2({language:"zh-CN",allowClear:true,minimumResultsForSearch: Infinity});
            var $maintenanceTypeChange = model.find(".maintenanceType");
            $maintenanceTypeChange.on("change", function (e) {
                if(model.find(".maintenanceType").val() == 1){
                    model.find(".send-image-div").removeClass("hide");
                    model.find(".send-div").removeClass("hide");
                    model.find(".send-number-div").removeClass("hide");
                }else{
                    model.find(".files-upload").val('');
                    model.find(".send-image-div").addClass("hide");
                    model.find(".send-div").addClass("hide");
                    model.find(".send-number-div").addClass("hide");
                    model.find(".hospitalSendDate").val('');
                    model.find(".hospitalSendNumber").val('');
                }
            });

            model.find(".hospitalSendDate").datetimepicker({
                autoclose: true,
                todayHighlight:true,
                language:'zh-CN',
                forceParse:true,
                minuteStep:1,
                todayBtn:true,
                fileDateEnd : new Date()
            });

            model.find(".files-upload").fileinput({
                language: 'zh', //设置语言
                enctype: 'multipart/form-data',
                showUpload: false, //是否显示上传按钮
                showCaption: false,	//是否显示标题
                showRemove: false,
                browseClass: "btn btn-info", //按钮样式
                maxFileCount:1,	//允许同时上传的最大文件个数
                allowedFileExtensions: ['jpg', 'gif', 'png','bmp'],//接收的文件后缀
                allowedFileTypes: ['jpg', 'gif', 'png','bmp'],
                msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！"
            });
        }

        model.find(".addDispatchInfoFromOwn").find(".engineerId").change(function(){
            var engineer = $(this).find("option:selected").text();
            model.find(".addDispatchInfoFromOwn").find(".engineer").val(engineer);
        });

        // 点击维修商工程工程师下拉框获取工程师名字事件
        model.find(".addDispatchInfoFromProvider").find(".engineerId").change(function(){
            var engineer = $(this).find("option:selected").text();
            model.find(".addDispatchInfoFromProvider").find(".engineer").val(engineer);
        });

        model.find('.serviceProviderId').off().change(function () {
            var obj = this;
            var engineerId = model.find(".addDispatchInfoFromProvider").find(".engineerId").html('').val('');
            $.ajax({
                type:'POST',
                url:basePath + '/repair/queryUserIdNameList',
                data: {"serviceProviderId":$(obj).val()},										// 参数：维修商ID
                dataType:'json',
                success:function(data){
                    // 再开始重新加载option
                    if(data!=null){
                        for (var i = 0; i < data.length; i++) {
                            engineerId.append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
                        }
                    }
                    engineerId.val(null).trigger("change");
                }
            });
        });

        if (messageObj) {
            model.iziModal('setTitle', '报修处理 ' + messageObj.assetsName + '(' + messageObj.department + ')' + messageObj.repairStatus + messageObj.repairTime);
        } else {
            model.iziModal('setTitle', '报修处理');
        }
        model.iziModal('open');
        model.find(".addDispatchInfoFromOwn").find(".id").val(id);				// 給指定的from表單賦值（自己修）
        model.find(".addDispatchInfoFromProvider").find(".id").val(id);			// 給指定的from表單賦值（維修商修）
        clickQueryMaintainer();											// 查询维修商
        clickQueryUserNameId();											// 本医院工程师


        // 查询报修信息以及设备信息
        $.ajax({
            type:'POST',
            url: basePath + '/repair/queryRepairView',
            data: {id: id}, 	// 参数
            dataType:'json',
            success:function(data){
                model.find(".bxclAssetsName").html(data.assetsName);		// 设备名称
                model.find(".bxclModel").html(data.model);				// 设备型号
                model.find(".bxclDepartment").html(data.department);		// 科室名称
                model.find(".bxclCategory").html(data.category);			// 设备分类
                model.find(".bxclRepairTime").html(data.repairTime);		// 维修日期
                model.find(".bxclUserName").html(data.userName);			// 报修人姓名
                model.find(".bxclUserPhone").html(data.userPhone);		// 报修人电话
                model.find(".bxclFaultTime").html(data.faultTime);		// 故障时间
                model.find(".bxclFault").html(data.fault);				// 故障描述
                model.find(".assetsCount").html(data.assetsCount);		// 设备维修次数
                model.find(".assetsId").val(data.assetsId);				// 设备ID
                var thumbnail1 = model.find('.thumbnail1');
                if (data.assetsPhotos) {
                    thumbnail1.show();
                    thumbnail1.thumbnail({imgs:data.assetsPhotos.split(',')});
                } else {
                    thumbnail1.hide();
                }
                var thumbnail2 = model.find('.thumbnail2');
                if (data.repairPhotos || data.phots) {
                    thumbnail2.show();
                    thumbnail2.thumbnail({imgs:(data.repairPhotos || data.phots).split(',')});
                } else {
                    thumbnail2.hide();
                }
            }
        });
        model.find(".contractAssets").html("");
        // 查询合同信息
        $.ajax({
            url: basePath + '/contract/getContractInfo',
            data: {assetsId: assetsId},
            type: 'POST',
            success:function(data){
                if(data.ret){
                    if(data.data){
                        model.find(".contact-number-a").text(data.data.contractNo || '');
                        /*if(data.data.contractNo){
                            model.find(".contact-number-a").attr("href","../contract/queryContractInfoById?class="+data.data.id);
                        }*/
                        /*model.find(".contact-person-a").text(data.data.contactPerson || '');
                        model.find(".contact-phone-a").text(data.data.contactPhone || '');
                        model.find(".service-provide-a").text(data.data.secondParty || '');*/
                    }
                }
            }
        });

        // 院内维修校验
        function own(){
            model.find('.addDispatchInfoFromOwn').bootstrapValidator({
                excluded: [':disabled', ':hidden', ':not(:visible)'],
                live: 'enabled',
                message: '非有效值',
                fields: {
                    card: {
                        validators: {
                            notEmpty: {
                                message: '不能为空'
                            }
                        }
                    },
                    engineerId:{
                        validators: {
                            notEmpty: {
                                message: '请选择工程师'
                            }
                        }
                    },
                    cost:{
                        validators: {
                            regexp: {
                                regexp: /^[0-9]\d*(\.\d{1,2})?$/,
                                message: '请输入正确的金额格式'
                            },stringLength: {
                                max: 10,
                                message: '最多输入10个字符'
                            }
                        }
                    },
                    remark:{
                        validators: {
                            stringLength: {
                                max: 200,
                                message: '最多输入200个字符'
                            }
                        }
                    }
                }
            });
        }
        // 维修商维修校验
        function provider(){
            model.find('.addDispatchInfoFromProvider').bootstrapValidator({
                excluded: [':disabled', ':hidden', ':not(:visible)'],
                live: 'enabled',
                message: '非有效值',
                fields: {
                    card: {
                        validators: {
                            notEmpty: {
                                message: '不能为空'
                            }
                        }
                    },
                    serviceProviderId:{
                        validators: {
                            notEmpty: {
                                message: '请选择维修商'
                            }
                        }
                    },
                    otherEngineer:{
                        validators: {
                            stringLength: {
                                max: 50,
                                message: '最多输入50个字符'
                            }
                        }
                    },
                    remark:{
                        validators: {
                            stringLength: {
                                max: 200,
                                message: '最多输入200个字符'
                            }
                        }
                    }
                }
            });
        }
        // 查询维修商
        function clickQueryMaintainer(){
            $.ajax({
                type: 'GET',
                url: basePath + '/serviceProvider/queryServiceProviderHospitalList',
                data: {"flag":'maintainer',deviceId: assetsId},
                dataType:'json',
                success:function(data){
                    // 默认进来清空option
                    var select = model.find(".addDispatchInfoFromProvider").find(".serviceProviderId").html("").append("<option value=''>请选择</option>");
                    if(data.ret == 200 && data.data != null){
                        var dataArray = data.data.list;
                        var title, color;
                        var str = '';
                        for (var i = 0; i < dataArray.length; i++) {
                            if (dataArray[i].contactPerson) {
                                title = '联系人：' + (dataArray[i].contactPerson || '-') + '  联系电话：' + (dataArray[i].contactPhone || '-');
                            } else if (dataArray[i].contactPhone) {
                                title = '联系人：' + (dataArray[i].contactPerson || '-') + '  联系电话：' + (dataArray[i].contactPhone || '-');
                            } else {
                                title = '联系人：-  联系电话：-';
                            }
                            if (dataArray[i].id === data.data.lastServer) {
                                color = ' style="color:#ad40ec"';
                                str = '(上次维修商)';
                            } else if (dataArray[i].id === data.data.contractServer) {
                                color = ' style="color:#1e6ce0"';
                                str = '(合同维修商)';
                            } else {
                                color = '';
                                str = '';
                            }
                            select.append("<option"+color+" title='" + title + "' value='"+dataArray[i].id+"'>"+dataArray[i].name+str+"</option>");
                        }
                        if (data.data.lastServer) {
                            select.val(data.data.lastServer).trigger('change');
                        } else if (data.data.contractServer) {
                            select.val(data.data.contractServer).trigger('change');
                        }
                    }

                }
            });
        }
        // 查询自己医院下的工程师
        function clickQueryUserNameId(){
            var select = model.find(".addDispatchInfoFromOwn .engineerId").html("").append("<option value=''>请选择</option>");
            $.ajax({
                type:'GET',
                url: basePath + '/repair/queryUserNameId',
                dataType:'json',
                success:function(data){
                    for (var i = 0; i < data.length; i++) {
                        select.append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
                    }
                }
            });
        }

        /* 提交 */
        model.find('.cancel, .iziModal-button-close').off().click(function (){
            if (isWebsocket) {
                messageObjArr[messageObjArr.index].isDoNow = true;
                dealPushMessage();
            }
        });
        model.find('.cancel').off().click(function (){
            if (isBatchDeal) {
                dealBatchDeal();
            } else {
                model.iziModal('close');
            }
        });
        model.find('.save').off().click(function (){
            var formData = new FormData(model.find(".addDispatchInfoFromProvider")[0]);
            $.ajax({
                url: basePath + '/repair/checkServiceProvider',
                type: 'POST',
                data: formData,//整个表单提交
                async: false,
                cache: false,
                contentType: false,
                processData: false,	//默认为true 异步
                success:function(data){
                    try {
                        if (data.ret == 1) {
                            new $.flavr({
                                closeOverlay : true,
                                closeEsc : true,
                                content : '该设备正在维修中确定再次报修处理吗？',
                                buttons:[
                                    {text:'取消',style:'info',action:function(){}},
                                    {text:'确定', style:'primary', action:function(){
                                            clickAddDispatchInfoProvider();
                                        }
                                    }
                                ]
                            });
                        } else {
                            clickAddDispatchInfoProvider();
                        }
                    } catch (error) {
                        new $.flavr({content:"操作遇到问题",closeOverlay:true,closeEsc:true,autoclose:true,timeout:1500,buttons:[{text:'确定',style:'danger',action:function(){}}]});
                        b2 = false;
                    }
                },
                failure : function() {
                    new $.flavr({content:"操作遇到问题",closeOverlay:true,closeEsc:true,autoclose:true,timeout:1500,buttons:[{text:'操作失败',style:'danger',action:function(){}}]});
                    b2 = false;
                }
            });
        });
        var b1 = false;
        model.find('.saveRegion').off().click(function (){
            var _self = this;
            if(b1 == false){
                model.find('.addDispatchInfoFromOwn').bootstrapValidator('validate');
                if(model.find('.addDispatchInfoFromOwn').data('bootstrapValidator').isValid()){
                    var formData = new FormData(model.find('.addDispatchInfoFromOwn')[0]);
                    b1 = true;
                    $(this).button('loading');
                    // 执行确认操作
                    $.ajax({
                        url: basePath + '/repair/addDispatchInfo',
                        type: 'POST',
                        data: formData,//整个表单提交
                        async : false, 	//默认为true 异步
                        cache: false,
                        contentType: false,
                        processData: false,	//默认为true 异步
                        success:function(data){
                            try {
                                $(_self).button('reset');
                                if (data.ret == 1) {
                                    model.iziModal('close');
                                    new $.flavr({content:data.msg,closeOverlay:true,closeEsc:true,autoclose:true,timeout:1500,buttons:[{text:'确定',style:'success',action:function(){}}]});
                                    b1= true;
                                } else {
                                    new $.flavr({content:data.msg,closeOverlay:true,closeEsc:true,autoclose:true,timeout:1500,buttons:[{text:'确定',style:'danger',action:function(){}}]});
                                    b1 = false;
                                }
                                if (isBatchDeal) {
                                    dealBatchDeal();
                                } else if (isWebsocket) {
                                    model.iziModal('close');
                                    messageObjArr[messageObjArr.index].isDoNow = true;
                                    dealPushMessage();
                                } else {
                                    model.iziModal('close');
                                }
                            } catch (error) {
                                $(_self).button('reset');
                                new $.flavr({content:"操作遇到问题",closeOverlay:true,closeEsc:true,autoclose:true,timeout:1500,buttons:[{text:'确定',style:'danger',action:function(){}}]});
                                b1 = false;
                            }
                        },
                        failure : function() {
                            $(_self).button('reset');
                            new $.flavr({content:"操作遇到问题",closeOverlay:true,closeEsc:true,autoclose:true,timeout:1500,buttons:[{text:'操作失败',style:'danger',action:function(){}}]});
                            b1 = false;
                        }
                    });
                }
            }
        });
        var b2 = false;
        function clickAddDispatchInfoProvider(){
            if(b2 == false){
                model.find('.addDispatchInfoFromProvider').bootstrapValidator('validate');
                if(model.find('.addDispatchInfoFromProvider').data('bootstrapValidator').isValid()){
                    b2 = true;
                    // 执行确认操作
                    var formData = new FormData(model.find('.addDispatchInfoFromProvider')[0]);
                    $.ajax({
                        url: basePath + '/repair/addDispatchInfo',
                        type:'POST',
                        data: formData,//整个表单提交
                        async: false,
                        cache: false,
                        contentType: false,
                        processData: false,	//默认为true 异步
                        success:function(data){
                            try {
                                if (data.ret == 1) {
                                    new $.flavr({content:data.msg,closeOverlay:true,closeEsc:true,autoclose:true,timeout:1500,buttons:[{text:'确定',style:'success',action:function(){}}]});
                                    b2= true;
                                } else {
                                    new $.flavr({content:data.msg,closeOverlay:true,closeEsc:true,autoclose:true,timeout:1500,buttons:[{text:'确定',style:'danger',action:function(){}}]});
                                    b2 = false;
                                }
                                if (isBatchDeal) {
                                    dealBatchDeal();
                                } else if (isWebsocket) {
                                    model.iziModal('close');
                                    messageObjArr[messageObjArr.index].isDoNow = true;
                                    dealPushMessage();
                                } else {
                                    model.iziModal('close');
                                }

                                loading(function () {
                                    queryWarning();
                                    for(var i = 1; i < 8; i++) {
                                        queryWarningList(i);
                                    }
                                });
                            } catch (error) {
                                console.log(error);
                            }
                        },
                        failure : function() {
                            new $.flavr({content:"操作遇到问题",closeOverlay:true,closeEsc:true,autoclose:true,timeout:1500,buttons:[{text:'操作失败',style:'danger',action:function(){}}]});
                            b2 = false;
                        }
                    });
                }
            }
        }

        /*
        * 维修历史模态框
        * */
        var repairHistoryTable = model.find('.repair-history-table');
        var repairHistory = model.find('.repair-history');
        // 查询记录
        $.ajax({
            type: 'POST',
            url: basePath + '/repair/queryRepairAssets',
            data: {"assetsId":assetsId}, 	// 参数设备ID
            dataType:'json',
            success:function(data){
                // 默认进来清空
                repairHistoryTable.find('thead').html("<tr>"
                    + "<th class='text-center text-muted'>故障时间</th>"
                    + "<th class='text-center text-muted'>故障描述</th>"
                    + "<th class='text-center text-muted'>更换备件</th>"
                    + "<th class='text-center text-muted'>报修时间</th>"
                    + "<th class='text-center text-muted'>修复时间</th>"
                    + "</tr>");
                var tbody = repairHistoryTable.find("tbody").html('');
                if(data==null || data==""){
                    repairHistory.slideUp();
                    tbody.append("<tr><td class='text-center text-primary' colspan='5' >无记录</td></tr>");
                }else if (data.length){
                    repairHistory.slideDown();
                    tbody.append("<tr>" +
                        "<td class='text-muted text-center'>"+fixStr(data[0].faultTime)+"</td>" +
                        "<td class='text-muted text-center'>"+fixStr(data[0].fault)+"</td>" +
                        "<td class='text-muted text-center'>"+fixStr(data[0].partName)+"</td>" +
                        "<td class='text-muted text-center'>"+fixStr(data[0].repairTime)+"</td>" +
                        "<td class='text-muted text-center'>"+fixStr(data[0].completeTime)+"</td>" +
                        "</tr>");
                    if (data.length > 1) {
                        tbody.append('<tr class="load-more" style="cursor: pointer;"><td class="text-center" style="color:#15b997;text-decoration: underline;" colspan="5">全部显示</td></tr>');
                        var loadMore = tbody.find('.load-more');
                        // 循环追加数据
                        loadMore.click(function () {
                            if (loadMore.hasClass('less')) {
                                loadMore.removeClass('less');
                                loadMore.find('td').html('全部显示');
                                var trs = tbody.find('tr');
                                for(var i = 1; i < trs.length - 1; i++) {
                                    trs.eq(i).remove();
                                }
                            } else {
                                loadMore.addClass('less');
                                loadMore.find('td').html('显示一条');
                                for (var i = 1; i < data.length; i++) {
                                    loadMore.before("<tr>" +
                                        "<td class='text-muted text-center'>" + fixStr(data[i].faultTime) + "</td>" +
                                        "<td class='text-muted text-center'>" + fixStr(data[i].fault) + "</td>" +
                                        "<td class='text-muted text-center'>" + fixStr(data[i].partName) + "</td>" +
                                        "<td class='text-muted text-center'>" + fixStr(data[i].repairTime) + "</td>" +
                                        "<td class='text-muted text-center'>" + fixStr(data[i].completeTime) + "</td>" +
                                        "</tr>");
                                }
                            }
                        });
                    }
                }
            }
        });

    };
})(jQuery);